/**
 * @author liangxi
 * @since 2024/4/11
 */

#include <iostream>
#include "SoldState.h"
#include "../GumballMachine.h"

GumballMachine *SoldState::getMGumballMachine() const {
    return mGumballMachine;
}

void SoldState::setMGumballMachine(GumballMachine *mGumballMachine) {
    SoldState::mGumballMachine = mGumballMachine;
}

void SoldState::dispense() {
    mGumballMachine->releaseBall();
    if (mGumballMachine->getMCount() > 0) {
        mGumballMachine->setState(mGumballMachine->getNoQuarterState());
    } else {
        std::cout << "Oops, out of gumball!\n";
        mGumballMachine->setState(mGumballMachine->getSoldOutState());
    }
}

void SoldState::turnCrank() {
    std::cout << "Turning twice does not get you another gumball!\n";
}

void SoldState::ejectQuarter() {
    std::cout << "Sorry,you already turned the crank\n";
}

void SoldState::insertQuarter() {
    std::cout << "Please wait,we are already giving you a gumball\n";
}
